home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectMusic / AudioPath / frmAudioPath.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  33.5 KB  |  958 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmAudioPath 
  5.    BorderStyle     =   3  'Fixed Dialog
  6.    Caption         =   "vbAudioPath Sample"
  7.    ClientHeight    =   5700
  8.    ClientLeft      =   720
  9.    ClientTop       =   780
  10.    ClientWidth     =   7965
  11.    Icon            =   "frmAudioPath.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   5700
  16.    ScaleWidth      =   7965
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.Timer tmrUpdate 
  19.       Interval        =   50
  20.       Left            =   8820
  21.       Top             =   660
  22.    End
  23.    Begin MSComDlg.CommonDialog cdlOpen 
  24.       Left            =   8820
  25.       Top             =   3120
  26.       _ExtentX        =   847
  27.       _ExtentY        =   847
  28.       _Version        =   393216
  29.    End
  30.    Begin VB.Frame fraPath 
  31.       Caption         =   "Audio Path 1 (Primary)"
  32.       Height          =   4095
  33.       Index           =   0
  34.       Left            =   0
  35.       TabIndex        =   31
  36.       Top             =   1500
  37.       Width           =   2595
  38.       Begin VB.TextBox txtPrimary 
  39.          Height          =   285
  40.          Left            =   60
  41.          Locked          =   -1  'True
  42.          TabIndex        =   16
  43.          Top             =   1620
  44.          Width           =   2175
  45.       End
  46.       Begin VB.CommandButton cmdAdd 
  47.          Caption         =   "..."
  48.          Height          =   300
  49.          Index           =   0
  50.          Left            =   2220
  51.          TabIndex        =   15
  52.          Top             =   1620
  53.          Width           =   315
  54.       End
  55.       Begin VB.CheckBox chkLoop 
  56.          Caption         =   "Loop"
  57.          Height          =   195
  58.          Index           =   0
  59.          Left            =   120
  60.          TabIndex        =   14
  61.          Top             =   2040
  62.          Width           =   735
  63.       End
  64.       Begin MSComctlLib.Slider sldX 
  65.          Height          =   135
  66.          Index           =   0
  67.          Left            =   300
  68.          TabIndex        =   18
  69.          Top             =   3360
  70.          Width           =   2235
  71.          _ExtentX        =   3942
  72.          _ExtentY        =   238
  73.          _Version        =   393216
  74.          Min             =   -20
  75.          Max             =   20
  76.          TickFrequency   =   5
  77.       End
  78.       Begin VB.CommandButton cmdStop 
  79.          Caption         =   "Stop"
  80.          Height          =   315
  81.          Index           =   0
  82.          Left            =   900
  83.          TabIndex        =   13
  84.          Top             =   1980
  85.          Width           =   795
  86.       End
  87.       Begin VB.CommandButton cmdPlay 
  88.          Caption         =   "Play"
  89.          Height          =   315
  90.          Index           =   0
  91.          Left            =   1740
  92.          TabIndex        =   12
  93.          Top             =   1980
  94.          Width           =   795
  95.       End
  96.       Begin MSComctlLib.Slider sldY 
  97.          Height          =   135
  98.          Index           =   0
  99.          Left            =   300
  100.          TabIndex        =   19
  101.          Top             =   3600
  102.          Width           =   2235
  103.          _ExtentX        =   3942
  104.          _ExtentY        =   238
  105.          _Version        =   393216
  106.          Min             =   -20
  107.          Max             =   20
  108.          TickFrequency   =   5
  109.       End
  110.       Begin MSComctlLib.Slider sldZ 
  111.          Height          =   135
  112.          Index           =   0
  113.          Left            =   300
  114.          TabIndex        =   20
  115.          Top             =   3840
  116.          Width           =   2235
  117.          _ExtentX        =   3942
  118.          _ExtentY        =   238
  119.          _Version        =   393216
  120.          Min             =   -20
  121.          Max             =   20
  122.          TickFrequency   =   5
  123.       End
  124.       Begin MSComctlLib.Slider sldVolume 
  125.          Height          =   135
  126.          Index           =   0
  127.          Left            =   120
  128.          TabIndex        =   17
  129.          Top             =   2940
  130.          Width           =   2415
  131.          _ExtentX        =   4260
  132.          _ExtentY        =   238
  133.          _Version        =   393216
  134.          LargeChange     =   500
  135.          SmallChange     =   100
  136.          Min             =   -6000
  137.          Max             =   0
  138.          TickFrequency   =   1000
  139.       End
  140.       Begin VB.Label lbl 
  141.          BackStyle       =   0  'Transparent
  142.          Caption         =   $"frmAudioPath.frx":0442
  143.          Height          =   1035
  144.          Index           =   21
  145.          Left            =   120
  146.          TabIndex        =   53
  147.          Top             =   240
  148.          Width           =   2415
  149.       End
  150.       Begin VB.Label lbl 
  151.          BackStyle       =   0  'Transparent
  152.          Caption         =   "Z"
  153.          Height          =   255
  154.          Index           =   10
  155.          Left            =   120
  156.          TabIndex        =   42
  157.          Top             =   3780
  158.          Width           =   195
  159.       End
  160.       Begin VB.Label lbl 
  161.          BackStyle       =   0  'Transparent
  162.          Caption         =   "Y"
  163.          Height          =   255
  164.          Index           =   9
  165.          Left            =   120
  166.          TabIndex        =   41
  167.          Top             =   3600
  168.          Width           =   255
  169.       End
  170.       Begin VB.Label lbl 
  171.          BackStyle       =   0  'Transparent
  172.          Caption         =   "X"
  173.          Height          =   255
  174.          Index           =   8
  175.          Left            =   120
  176.          TabIndex        =   40
  177.          Top             =   3360
  178.          Width           =   195
  179.       End
  180.       Begin VB.Label lbl 
  181.          BackStyle       =   0  'Transparent
  182.          Caption         =   "3D Positioning"
  183.          Height          =   255
  184.          Index           =   7
  185.          Left            =   120
  186.          TabIndex        =   39
  187.          Top             =   3120
  188.          Width           =   2415
  189.       End
  190.       Begin VB.Label lbl 
  191.          BackStyle       =   0  'Transparent
  192.          Caption         =   "Volume (hundredths of a decibel)"
  193.          Height          =   255
  194.          Index           =   6
  195.          Left            =   120
  196.          TabIndex        =   38
  197.          Top             =   2700
  198.          Width           =   2415
  199.       End
  200.       Begin VB.Label lbl 
  201.          BackStyle       =   0  'Transparent
  202.          Caption         =   "Audio Path Settings"
  203.          Height          =   255
  204.          Index           =   3
  205.          Left            =   120
  206.          TabIndex        =   35
  207.          Top             =   2460
  208.          Width           =   2415
  209.       End
  210.       Begin VB.Label lbl 
  211.          BackStyle       =   0  'Transparent
  212.          Caption         =   "File in Audio Path"
  213.          Height          =   255
  214.          Index           =   0
  215.          Left            =   120
  216.          TabIndex        =   32
  217.          Top             =   1380
  218.          Width           =   2415
  219.       End
  220.    End
  221.    Begin VB.Frame fraPath 
  222.       Caption         =   "Audio Path 3 (Secondary)"
  223.       Height          =   4095
  224.       Index           =   2
  225.       Left            =   5280
  226.       TabIndex        =   30
  227.       Top             =   1500
  228.       Width           =   2595
  229.       Begin VB.CheckBox chkLoop 
  230.          Caption         =   "Loop"
  231.          Height          =   195
  232.          Index           =   2
  233.          Left            =   1740
  234.          TabIndex        =   2
  235.          Top             =   1440
  236.          Width           =   735
  237.       End
  238.       Begin VB.CommandButton cmdStop 
  239.          Caption         =   "Stop"
  240.          Height          =   315
  241.          Index           =   2
  242.          Left            =   1680
  243.          TabIndex        =   0
  244.          Top             =   2100
  245.          Width           =   795
  246.       End
  247.       Begin VB.CommandButton cmdPlay 
  248.          Caption         =   "Play"
  249.          Height          =   315
  250.          Index           =   2
  251.          Left            =   1680
  252.          TabIndex        =   1
  253.          Top             =   1740
  254.          Width           =   795
  255.       End
  256.       Begin VB.CommandButton cmdRemove 
  257.          Caption         =   "Remove"
  258.          Height          =   315
  259.          Index           =   2
  260.          Left            =   1680
  261.          TabIndex        =   3
  262.          Top             =   960
  263.          Width           =   795
  264.       End
  265.       Begin VB.CommandButton cmdAdd 
  266.          Caption         =   "Add"
  267.          Height          =   315
  268.          Index           =   2
  269.          Left            =   1680
  270.          TabIndex        =   4
  271.          Top             =   600
  272.          Width           =   795
  273.       End
  274.       Begin VB.ListBox lstPath 
  275.          Height          =   1815
  276.          Index           =   2
  277.          Left            =   120
  278.          TabIndex        =   5
  279.          Top             =   600
  280.          Width           =   1515
  281.       End
  282.       Begin MSComctlLib.Slider sldVolume 
  283.          Height          =   135
  284.          Index           =   2
  285.          Left            =   60
  286.          TabIndex        =   25
  287.          Top             =   2940
  288.          Width           =   2415
  289.          _ExtentX        =   4260
  290.          _ExtentY        =   238
  291.          _Version        =   393216
  292.          LargeChange     =   500
  293.          SmallChange     =   100
  294.          Min             =   -6000
  295.          Max             =   0
  296.          TickFrequency   =   1000
  297.       End
  298.       Begin MSComctlLib.Slider sldX 
  299.          Height          =   135
  300.          Index           =   2
  301.          Left            =   240
  302.          TabIndex        =   26
  303.          Top             =   3360
  304.          Width           =   2235
  305.          _ExtentX        =   3942
  306.          _ExtentY        =   238
  307.          _Version        =   393216
  308.          Min             =   -20
  309.          Max             =   20
  310.          TickFrequency   =   5
  311.       End
  312.       Begin MSComctlLib.Slider sldY 
  313.          Height          =   135
  314.          Index           =   2
  315.          Left            =   240
  316.          TabIndex        =   27
  317.          Top             =   3600
  318.          Width           =   2235
  319.          _ExtentX        =   3942
  320.          _ExtentY        =   238
  321.          _Version        =   393216
  322.          Min             =   -20
  323.          Max             =   20
  324.          TickFrequency   =   5
  325.       End
  326.       Begin MSComctlLib.Slider sldZ 
  327.          Height          =   135
  328.          Index           =   2
  329.          Left            =   240
  330.          TabIndex        =   28
  331.          Top             =   3840
  332.          Width           =   2235
  333.          _ExtentX        =   3942
  334.          _ExtentY        =   238
  335.          _Version        =   393216
  336.          Min             =   -20
  337.          Max             =   20
  338.          TickFrequency   =   5
  339.       End
  340.       Begin VB.Label lbl 
  341.          BackStyle       =   0  'Transparent
  342.          Caption         =   "Z"
  343.          Height          =   255
  344.          Index           =   20
  345.          Left            =   60
  346.          TabIndex        =   52
  347.          Top             =   3780
  348.          Width           =   195
  349.       End
  350.       Begin VB.Label lbl 
  351.          BackStyle       =   0  'Transparent
  352.          Caption         =   "Y"
  353.          Height          =   255
  354.          Index           =   19
  355.          Left            =   60
  356.          TabIndex        =   51
  357.          Top             =   3600
  358.          Width           =   255
  359.       End
  360.       Begin VB.Label lbl 
  361.          BackStyle       =   0  'Transparent
  362.          Caption         =   "X"
  363.          Height          =   255
  364.          Index           =   18
  365.          Left            =   60
  366.          TabIndex        =   50
  367.          Top             =   3360
  368.          Width           =   195
  369.       End
  370.       Begin VB.Label lbl 
  371.          BackStyle       =   0  'Transparent
  372.          Caption         =   "3D Positioning"
  373.          Height          =   255
  374.          Index           =   17
  375.          Left            =   60
  376.          TabIndex        =   49
  377.          Top             =   3120
  378.          Width           =   2415
  379.       End
  380.       Begin VB.Label lbl 
  381.          BackStyle       =   0  'Transparent
  382.          Caption         =   "Volume (hundredths of a decibel)"
  383.          Height          =   255
  384.          Index           =   16
  385.          Left            =   60
  386.          TabIndex        =   48
  387.          Top             =   2700
  388.          Width           =   2415
  389.       End
  390.       Begin VB.Label lbl 
  391.          BackStyle       =   0  'Transparent
  392.          Caption         =   "Audio Path Settings"
  393.          Height          =   255
  394.          Index           =   5
  395.          Left            =   120
  396.          TabIndex        =   37
  397.          Top             =   2460
  398.          Width           =   2415
  399.       End
  400.       Begin VB.Label lbl 
  401.          BackStyle       =   0  'Transparent
  402.          Caption         =   "Files in Audio Path"
  403.          Height          =   255
  404.          Index           =   2
  405.          Left            =   180
  406.          TabIndex        =   34
  407.          Top             =   240
  408.          Width           =   2415
  409.       End
  410.    End
  411.    Begin VB.Frame fraPath 
  412.       Caption         =   "Audio Path 2 (Secondary)"
  413.       Height          =   4095
  414.       Index           =   1
  415.       Left            =   2640
  416.       TabIndex        =   29
  417.       Top             =   1500
  418.       Width           =   2595
  419.       Begin VB.CheckBox chkLoop 
  420.          Caption         =   "Loop"
  421.          Height          =   195
  422.          Index           =   1
  423.          Left            =   1740
  424.          TabIndex        =   8
  425.          Top             =   1440
  426.          Width           =   735
  427.       End
  428.       Begin MSComctlLib.Slider sldX 
  429.          Height          =   135
  430.          Index           =   1
  431.          Left            =   240
  432.          TabIndex        =   22
  433.          Top             =   3360
  434.          Width           =   2235
  435.          _ExtentX        =   3942
  436.          _ExtentY        =   238
  437.          _Version        =   393216
  438.          Min             =   -20
  439.          Max             =   20
  440.          TickFrequency   =   5
  441.       End
  442.       Begin MSComctlLib.Slider sldVolume 
  443.          Height          =   135
  444.          Index           =   1
  445.          Left            =   60
  446.          TabIndex        =   21
  447.          Top             =   2940
  448.          Width           =   2415
  449.          _ExtentX        =   4260
  450.          _ExtentY        =   238
  451.          _Version        =   393216
  452.          LargeChange     =   500
  453.          SmallChange     =   100
  454.          Min             =   -6000
  455.          Max             =   0
  456.          TickFrequency   =   1000
  457.       End
  458.       Begin VB.CommandButton cmdStop 
  459.          Caption         =   "Stop"
  460.          Height          =   315
  461.          Index           =   1
  462.          Left            =   1680
  463.          TabIndex        =   6
  464.          Top             =   2100
  465.          Width           =   795
  466.       End
  467.       Begin VB.CommandButton cmdPlay 
  468.          Caption         =   "Play"
  469.          Height          =   315
  470.          Index           =   1
  471.          Left            =   1680
  472.          TabIndex        =   7
  473.          Top             =   1740
  474.          Width           =   795
  475.       End
  476.       Begin VB.CommandButton cmdRemove 
  477.          Caption         =   "Remove"
  478.          Height          =   315
  479.          Index           =   1
  480.          Left            =   1680
  481.          TabIndex        =   9
  482.          Top             =   960
  483.          Width           =   795
  484.       End
  485.       Begin VB.CommandButton cmdAdd 
  486.          Caption         =   "Add"
  487.          Height          =   315
  488.          Index           =   1
  489.          Left            =   1680
  490.          TabIndex        =   10
  491.          Top             =   600
  492.          Width           =   795
  493.       End
  494.       Begin VB.ListBox lstPath 
  495.          Height          =   1815
  496.          Index           =   1
  497.          Left            =   120
  498.          TabIndex        =   11
  499.          Top             =   600
  500.          Width           =   1515
  501.       End
  502.       Begin MSComctlLib.Slider sldY 
  503.          Height          =   135
  504.          Index           =   1
  505.          Left            =   240
  506.          TabIndex        =   23
  507.          Top             =   3600
  508.          Width           =   2235
  509.          _ExtentX        =   3942
  510.          _ExtentY        =   238
  511.          _Version        =   393216
  512.          Min             =   -20
  513.          Max             =   20
  514.          TickFrequency   =   5
  515.       End
  516.       Begin MSComctlLib.Slider sldZ 
  517.          Height          =   135
  518.          Index           =   1
  519.          Left            =   240
  520.          TabIndex        =   24
  521.          Top             =   3840
  522.          Width           =   2235
  523.          _ExtentX        =   3942
  524.          _ExtentY        =   238
  525.          _Version        =   393216
  526.          Min             =   -20
  527.          Max             =   20
  528.          TickFrequency   =   5
  529.       End
  530.       Begin VB.Label lbl 
  531.          BackStyle       =   0  'Transparent
  532.          Caption         =   "Z"
  533.          Height          =   255
  534.          Index           =   15
  535.          Left            =   60
  536.          TabIndex        =   47
  537.          Top             =   3780
  538.          Width           =   195
  539.       End
  540.       Begin VB.Label lbl 
  541.          BackStyle       =   0  'Transparent
  542.          Caption         =   "Y"
  543.          Height          =   255
  544.          Index           =   14
  545.          Left            =   60
  546.          TabIndex        =   46
  547.          Top             =   3600
  548.          Width           =   255
  549.       End
  550.       Begin VB.Label lbl 
  551.          BackStyle       =   0  'Transparent
  552.          Caption         =   "X"
  553.          Height          =   255
  554.          Index           =   13
  555.          Left            =   60
  556.          TabIndex        =   45
  557.          Top             =   3360
  558.          Width           =   195
  559.       End
  560.       Begin VB.Label lbl 
  561.          BackStyle       =   0  'Transparent
  562.          Caption         =   "3D Positioning"
  563.          Height          =   255
  564.          Index           =   12
  565.          Left            =   60
  566.          TabIndex        =   44
  567.          Top             =   3120
  568.          Width           =   2415
  569.       End
  570.       Begin VB.Label lbl 
  571.          BackStyle       =   0  'Transparent
  572.          Caption         =   "Volume (hundredths of a decibel)"
  573.          Height          =   255
  574.          Index           =   11
  575.          Left            =   60
  576.          TabIndex        =   43
  577.          Top             =   2700
  578.          Width           =   2415
  579.       End
  580.       Begin VB.Label lbl 
  581.          BackStyle       =   0  'Transparent
  582.          Caption         =   "Audio Path Settings"
  583.          Height          =   255
  584.          Index           =   4
  585.          Left            =   120
  586.          TabIndex        =   36
  587.          Top             =   2460
  588.          Width           =   2415
  589.       End
  590.       Begin VB.Label lbl 
  591.          BackStyle       =   0  'Transparent
  592.          Caption         =   "Files in Audio Path"
  593.          Height          =   255
  594.          Index           =   1
  595.          Left            =   180
  596.          TabIndex        =   33
  597.          Top             =   240
  598.          Width           =   2415
  599.       End
  600.    End
  601.    Begin VB.Label lbl 
  602.       BackStyle       =   0  'Transparent
  603.       Caption         =   "Audio Path Samples"
  604.       Height          =   255
  605.       Index           =   24
  606.       Left            =   600
  607.       TabIndex        =   56
  608.       Top             =   120
  609.       Width           =   2655
  610.    End
  611.    Begin VB.Label lbl 
  612.       BackStyle       =   0  'Transparent
  613.       Caption         =   "Copyright (C) 1999-2001 Microsoft Corporation, All Rights Reserved."
  614.       Height          =   195
  615.       Index           =   23
  616.       Left            =   600
  617.       TabIndex        =   55
  618.       Top             =   360
  619.       Width           =   7335
  620.    End
  621.    Begin VB.Image Image1 
  622.       Height          =   480
  623.       Left            =   60
  624.       Picture         =   "frmAudioPath.frx":04CC
  625.       Top             =   120
  626.       Width           =   480
  627.    End
  628.    Begin VB.Label lbl 
  629.       BackStyle       =   0  'Transparent
  630.       Caption         =   $"frmAudioPath.frx":090E
  631.       Height          =   795
  632.       Index           =   22
  633.       Left            =   60
  634.       TabIndex        =   54
  635.       Top             =   600
  636.       Width           =   7875
  637.    End
  638. Attribute VB_Name = "frmAudioPath"
  639. Attribute VB_GlobalNameSpace = False
  640. Attribute VB_Creatable = False
  641. Attribute VB_PredeclaredId = True
  642. Attribute VB_Exposed = False
  643. Option Explicit
  644. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  645. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  646. '  File:       frmAudioPath.frm
  647. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  648. 'Note the actual max files will be 1+ this constant (0 to Max)
  649. Private Const MAX_FILES_PER_AUDIO_PATH As Byte = 4
  650. 'First we need our directx object
  651. Private dx As New DirectX8
  652. 'And we need the audio paths we'll be using
  653. Private dmAudio(0 To 2) As DirectMusicAudioPath8
  654. 'Loader and Performance objects
  655. Private dmLoader As DirectMusicLoader8
  656. Private dmPerformance As DirectMusicPerformance8
  657. 'Each audio path can have up to 5 segments
  658. Private dmSegment(0 To 2, 0 To MAX_FILES_PER_AUDIO_PATH) As DirectMusicSegment8
  659. Private dmState(0 To 2, 0 To MAX_FILES_PER_AUDIO_PATH) As DirectMusicSegmentState8
  660. 'API declare for windows folder
  661. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  662. Private Sub InitAudio()
  663.     On Error GoTo FailedInit
  664.     Dim dmAParams As DMUS_AUDIOPARAMS
  665.     Dim lCount As Long
  666.     'First we'll create out loader and performance
  667.     Set dmPerformance = dx.DirectMusicPerformanceCreate
  668.     Set dmLoader = dx.DirectMusicLoaderCreate
  669.     'Now we'll init our audio, and create our audio paths
  670.     dmPerformance.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dmAParams
  671.     For lCount = 0 To 2
  672.         Set dmAudio(lCount) = dmPerformance.CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D, 128, True)
  673.         EnablePlayUI lCount, True
  674.     Next
  675.     Exit Sub
  676. FailedInit:
  677.     MsgBox "Could not initialize DirectMusic." & vbCrLf & "This sample will exit.", vbOKOnly Or vbInformation, "Exiting..."
  678.     Unload Me
  679. End Sub
  680. Private Sub Cleanup()
  681.     Dim lCount As Long, lCountInner As Long
  682.     'We need to clean up everything now
  683.     'First unload all of the segments
  684.     For lCount = 0 To 2
  685.         For lCountInner = 0 To MAX_FILES_PER_AUDIO_PATH
  686.             If Not dmSegment(lCount, lCountInner) Is Nothing Then
  687.                 'Stop the segment if it's playing
  688.                 dmPerformance.StopEx dmSegment(lCount, lCountInner), 0, 0
  689.                 'Unload the segment from the audio path
  690.                 dmSegment(lCount, lCountInner).Unload dmAudio(lCount)
  691.                 'Destroy the segment
  692.                 Set dmSegment(lCount, lCountInner) = Nothing
  693.                 'Destroy the state
  694.                 Set dmState(lCount, lCountInner) = Nothing
  695.             End If
  696.         Next
  697.     Next
  698.     For lCount = 0 To 2
  699.         'Destroy the audio path
  700.         Set dmAudio(lCount) = Nothing
  701.     Next
  702.     'Destroy the rest of our objects
  703.     Set dmLoader = Nothing
  704.     If Not (dmPerformance Is Nothing) Then dmPerformance.CloseDown
  705.     Set dmPerformance = Nothing
  706.     Set dx = Nothing
  707. End Sub
  708. Private Sub cmdAdd_Click(Index As Integer)
  709.     Static sCurDir As String
  710.     Static lFilter As Long
  711.     Dim lCount As Long
  712.     'Now we should load a segment
  713.     'First check to see if we already have enough segments
  714.     If Index > 0 Then
  715.         If lstPath(Index).ListCount > MAX_FILES_PER_AUDIO_PATH Then
  716.             MsgBox "You already have " & CStr(MAX_FILES_PER_AUDIO_PATH + 1) & " segments loaded on this audio path.  Please remove one before attempting to load another on this audio path.", vbOKOnly Or vbInformation, "Can't load."
  717.             Exit Sub
  718.         End If
  719.     End If
  720.         
  721.     'Ask them for a file to load
  722.     With cdlOpen
  723.         .flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
  724.         .FilterIndex = lFilter
  725.         .Filter = "Wave Files (*.wav)|*.wav|Music Files (*.mid;*.rmi)|*.mid;*.rmi|Segment Files (*.sgt)|*.sgt|All Audio Files|*.wav;*.mid;*.rmi;*.sgt|All Files (*.*)|*.*"
  726.         .FileName = vbNullString
  727.         If sCurDir = vbNullString Then
  728.             'Set the init folder to \windows\media if it exists.  If not, set it to the \windows folder
  729.             Dim sWindir As String
  730.             sWindir = Space$(255)
  731.             If GetWindowsDirectory(sWindir, 255) = 0 Then
  732.                 'We couldn't get the windows folder for some reason, use the c:\
  733.                 .InitDir = "C:\"
  734.             Else
  735.                 Dim sMedia As String
  736.                 sWindir = Left$(sWindir, InStr(sWindir, Chr$(0)) - 1)
  737.                 If Right$(sWindir, 1) = "\" Then
  738.                     sMedia = sWindir & "Media"
  739.                 Else
  740.                     sMedia = sWindir & "\Media"
  741.                 End If
  742.                 If Dir$(sMedia, vbDirectory) <> vbNullString Then
  743.                     .InitDir = sMedia
  744.                 Else
  745.                     .InitDir = sWindir
  746.                 End If
  747.             End If
  748.         Else
  749.             .InitDir = sCurDir
  750.         End If
  751.         .ShowOpen   ' Display the Open dialog box
  752.         If .FileName = vbNullString Then Exit Sub 'We didn't click anything exit
  753.         'Save the current information
  754.         sCurDir = GetFolder(.FileName)
  755.         dmLoader.SetSearchDirectory sCurDir
  756.         lFilter = .FilterIndex
  757.         On Local Error GoTo ErrOut
  758.         'Now lets try to create a segment
  759.         If Index > 0 Then
  760.             For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  761.                 If (dmSegment(Index, lCount) Is Nothing) Then
  762.                     Set dmSegment(Index, lCount) = dmLoader.LoadSegment(.FileName)
  763.                     If (Right$(.FileName, 4) = ".mid") Or (Right$(.FileName, 4) = ".rmi") Or (Right$(.FileName, 5) = ".midi") Then
  764.                         dmSegment(Index, lCount).SetStandardMidiFile
  765.                     End If
  766.                     dmSegment(Index, lCount).Download dmAudio(Index)
  767.                     Exit For
  768.                 End If
  769.             Next
  770.             'Now we can add this file
  771.             lstPath(Index).AddItem .FileName
  772.             lstPath(Index).ItemData(lstPath(Index).ListCount - 1) = ObjPtr(dmSegment(Index, lCount))
  773.         Else
  774.             Set dmSegment(Index, 0) = dmLoader.LoadSegment(.FileName)
  775.             If (Right$(.FileName, 4) = ".mid") Or (Right$(.FileName, 4) = ".rmi") Or (Right$(.FileName, 5) = ".midi") Then
  776.                 dmSegment(Index, 0).SetStandardMidiFile
  777.             End If
  778.             dmSegment(Index, 0).Download dmAudio(Index)
  779.             txtPrimary.Text = .FileName
  780.         End If
  781.         
  782.     End With
  783.     Exit Sub
  784. ErrOut:
  785.     MsgBox "An error occured trying to load this segment.", vbOKOnly Or vbInformation, "Not loaded."
  786. End Sub
  787. Private Sub cmdPlay_Click(Index As Integer)
  788.     Dim lCount As Long
  789.     If Index > 0 Then
  790.         If lstPath(Index).ListCount < 0 Then Exit Sub 'There is nothing to if nothing is select
  791.     ElseIf txtPrimary.Text = vbNullString Then
  792.         Exit Sub
  793.     End If
  794.         
  795.     'We can play our segments
  796.     For lCount = 0 To MAX_FILES_PER_AUDIO_PATH 'Max num of sounds
  797.         If Not dmSegment(Index, lCount) Is Nothing Then 'Nothing to do if there is no segment loaded
  798.             If chkLoop(Index).Value = vbChecked Then
  799.                 dmSegment(Index, lCount).SetRepeats INFINITE
  800.             Else
  801.                 dmSegment(Index, lCount).SetRepeats 0
  802.             End If
  803.             If Index = 0 Then
  804.                 'We must play the segment as default for the primary path
  805.                 Set dmState(Index, lCount) = dmPerformance.PlaySegmentEx(dmSegment(Index, lCount), DMUS_SEGF_DEFAULT, 0, , dmAudio(Index))
  806.             Else
  807.                 'We must play the segment as secondary if we want multiple segments to repeat in the same
  808.                 'audio path.
  809.                 Set dmState(Index, lCount) = dmPerformance.PlaySegmentEx(dmSegment(Index, lCount), DMUS_SEGF_SECONDARY, 0, , dmAudio(Index))
  810.             End If
  811.         End If
  812.     Next
  813.     UpdateVolume Index
  814.     EnablePlayUI Index, False
  815.     cmdStop(Index).SetFocus
  816. End Sub
  817. Private Sub cmdRemove_Click(Index As Integer)
  818.     Dim lCount As Long
  819.     Dim oTempSeg As DirectMusicSegment8
  820.     Dim lPtr As Long
  821.     If lstPath(Index).ListIndex < 0 Then Exit Sub 'There is nothing to if nothing is select
  822.     'Remove this item
  823.     lPtr = lstPath(Index).ItemData(lstPath(Index).ListIndex)
  824.     For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  825.         If lPtr = ObjPtr(dmSegment(Index, lCount)) Then
  826.             dmPerformance.StopEx dmSegment(Index, lCount), 0, 0
  827.             dmSegment(Index, lCount).Unload dmAudio(Index)
  828.             Set dmSegment(Index, lCount) = Nothing
  829.         End If
  830.     Next
  831.     For lCount = lstPath(Index).ListCount - 1 To 0 Step -1
  832.         If lstPath(Index).ItemData(lCount) = lPtr Then
  833.             lstPath(Index).RemoveItem lCount
  834.         End If
  835.     Next
  836. End Sub
  837. Private Sub cmdStop_Click(Index As Integer)
  838.     Dim lCount As Long
  839.     If Index > 0 Then
  840.         If lstPath(Index).ListCount < 0 Then Exit Sub 'There is nothing to if nothing is select
  841.     ElseIf txtPrimary.Text = vbNullString Then
  842.         Exit Sub
  843.     End If
  844.     'We can stop our segments
  845.     For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  846.         If Not dmSegment(Index, lCount) Is Nothing Then 'Nothing to do if there is no segment loaded
  847.             dmPerformance.StopEx dmSegment(Index, lCount), 0, 0
  848.             Set dmState(Index, lCount) = Nothing
  849.         End If
  850.     Next
  851.     EnablePlayUI Index, True
  852.     cmdPlay(Index).SetFocus
  853. End Sub
  854. Private Sub Form_Load()
  855.     If App.PrevInstance Then 'We are already running an instance of this, exit
  856.         Dim sSave As String
  857.         'Activate the currently running instance
  858.         sSave = App.Title
  859.         App.Title = App.Title & "... duplicate instance."
  860.         Me.Caption = App.Title & "... duplicate instance."
  861.         AppActivate sSave
  862.         'Get rid of ourselves
  863.         Unload Me
  864.         End
  865.     End If
  866.     InitAudio
  867. End Sub
  868. Private Sub Form_Unload(Cancel As Integer)
  869.     Cleanup
  870. End Sub
  871. Private Function GetFolder(ByVal sFile As String) As String
  872.     Dim lCount As Long
  873.     For lCount = Len(sFile) To 1 Step -1
  874.         If Mid$(sFile, lCount, 1) = "\" Then
  875.             GetFolder = Left$(sFile, lCount)
  876.             Exit Function
  877.         End If
  878.     Next
  879.     GetFolder = vbNullString
  880. End Function
  881. Private Sub lstPath_DblClick(Index As Integer)
  882.     cmdRemove_Click Index
  883. End Sub
  884. Private Sub sldVolume_Click(Index As Integer)
  885.     UpdateVolume Index
  886. End Sub
  887. Private Sub sldVolume_Scroll(Index As Integer)
  888.     UpdateVolume Index
  889. End Sub
  890. Private Sub UpdateVolume(ByVal Index As Integer)
  891.     'Ok , we 're changing, let's get the buffer for this path, and set the 3D position
  892.     Dim dsb As DirectSoundSecondaryBuffer8
  893.     'Get a 3D Buffer
  894.     Set dsb = dmAudio(Index).GetObjectinPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0, GUID_ALL, 0, IID_DirectSoundSecondaryBuffer)
  895.     'Set the new position of the 3D Buffer (immediately)
  896.     dsb.SetVolume sldVolume(Index).Value
  897.     Set dsb = Nothing
  898. End Sub
  899. Private Sub Update3D(ByVal Index As Integer)
  900.     'Ok, we're changing, let's get the buffer for this path, and set the 3D position
  901.     Dim dsb As DirectSound3DBuffer8
  902.     'Get a 3D Buffer
  903.     Set dsb = dmAudio(Index).GetObjectinPath(DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0, GUID_ALL, 0, IID_DirectSound3DBuffer)
  904.     'Set the new position of the 3D Buffer (immediately)
  905.     dsb.SetPosition sldX(Index).Value / 5, sldY(Index).Value / 5, sldZ(Index).Value / 5, DS3D_IMMEDIATE
  906.     Set dsb = Nothing
  907. End Sub
  908. Private Sub sldX_Click(Index As Integer)
  909.     Update3D Index
  910. End Sub
  911. Private Sub sldX_Scroll(Index As Integer)
  912.     Update3D Index
  913. End Sub
  914. Private Sub sldY_Click(Index As Integer)
  915.     Update3D Index
  916. End Sub
  917. Private Sub sldY_Scroll(Index As Integer)
  918.     Update3D Index
  919. End Sub
  920. Private Sub sldZ_Click(Index As Integer)
  921.     Update3D Index
  922. End Sub
  923. Private Sub sldZ_Scroll(Index As Integer)
  924.     Update3D Index
  925. End Sub
  926. Public Sub EnablePlayUI(ByVal lIndex As Long, fEnable As Boolean)
  927.     'Enable/Disable the buttons
  928.     If fEnable Then
  929.         chkLoop(lIndex).Enabled = True
  930.         cmdStop(lIndex).Enabled = False
  931.         cmdPlay(lIndex).Enabled = True
  932.         cmdAdd(lIndex).Enabled = True
  933.         If lIndex > 0 Then cmdRemove(lIndex).Enabled = True
  934.     Else
  935.         chkLoop(lIndex).Enabled = False
  936.         cmdStop(lIndex).Enabled = True
  937.         cmdPlay(lIndex).Enabled = False
  938.         cmdAdd(lIndex).Enabled = False
  939.         If lIndex > 0 Then cmdRemove(lIndex).Enabled = False
  940.     End If
  941. End Sub
  942. Private Sub tmrUpdate_Timer()
  943.     Dim lCount As Long
  944.     Dim lIndex As Long
  945.     Dim fEnableIndex As Boolean
  946.     For lIndex = 0 To 2
  947.         fEnableIndex = True
  948.         For lCount = 0 To MAX_FILES_PER_AUDIO_PATH
  949.             If (Not (dmSegment(lIndex, lCount) Is Nothing)) And (Not (dmState(lIndex, lCount) Is Nothing)) Then
  950.                 If dmPerformance.IsPlaying(dmSegment(lIndex, lCount), dmState(lIndex, lCount)) Then
  951.                     fEnableIndex = False
  952.                 End If
  953.             End If
  954.         Next
  955.         EnablePlayUI lIndex, fEnableIndex
  956.     Next
  957. End Sub
  958.